----------------------------
-- Автор: Бабаев Антон Александрович
-- Имя компонента: CompAD9826control
--
-- Функциональное описание:
--    Управление АЦП AD9826
--
-- Компонент позволяет работать со светодиодами в нескольких режимах:
-- 1. Мигание всеми светодиодами одновременно
--    Regime - "01"
-- 2. Перемещение n-го количества светодиодов слава-направо, справа-налево
--    Regime - "10"
-- 3. Отображение содержимого памяти с использованием светодиодов
--    Regime - "11"
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use ieee.numeric_std.all;

entity CompLEDflashing is
generic (
 genFreqIn : integer := 108000000;
 genFreqOut : integer := 10;
 genNumLeds : integer := 27;
 genRegime : std_logic_vector := "01"
);
port (  
 Clk : in std_logic;
 GReset : in std_logic;
-- Read : in std_logic;
-- Write : in std_logic;
-- ChipSelect : in std_logic;
-- Address : in unsigned(4 downto 0);
-- ReadData : out unsigned(genNumLeds-1 downto 0);
-- WriteData : in unsigned(genNumLeds-1 downto 0);
 LedsOut : out std_logic_vector(genNumLeds-1 downto 0)
);
end CompLEDflashing;

architecture ArchLEDflashing of CompLEDflashing is 
--type ram_type is array(genNumLeds-15 downto 0) of unsigned(genNumLeds-1 downto 0);
--signal RAM : ram_type;
--signal ram_address, display_address : unsigned(3 downto 0);
--signal counter_delay : unsigned(genNumLeds-1 downto 0);
signal sigCount : std_logic_vector(31 downto 0);
begin
 process (clk)
 begin
  if (Clk'event and Clk='1') then
   if (GReset = '1') then
--    ReadData <= (others => '0');
--    display_address <= (others => '0');
    sigCount <= (others => '0');
--    counter_delay <= (others => '1');
   else
--	 case genRegime is
--	  when "01" =>
      if (sigCount = (genFreqIn/genFreqOut)) then
	    LedsOut <= (others => '0');
		 sigCount <= sigCount + 1;
	   elsif (sigCount = (2*genFreqIn/genFreqOut)) then
		 LedsOut <= (others => '1');
		 sigCount <= (others => '0');
      else
       sigCount <= sigCount + 1;
      end if;
--	  when "10" =>
--      if (sigCount = (genFreqIn/genFreqOut)) then
--	    LedsOut <= (others => '0');
--		 sigCount <= sigCount + 1;
--	   elsif (sigCount = (2*genFreqIn/genFreqOut)) then
--		 LedsOut <= (others => '1');
--		 sigCount <= (others => '0');
--      else
--       sigCount <= sigCount + 1;
--      end if;
--	  when "11" =>
--      if chipselect = '1' then
--       if address(4) = '0' then 
--       if (read = '1') then
--        readdata <= RAM(to_integer(ram_address));
--       elsif (write = '1') then
--        RAM(to_integer(ram_address)) <= writedata;
--       end if;
--      else
--       if write = '1' then
--        counter_delay <= writedata;
--       end if;
--      end if;
--     else
--      LedsOut <= RAM(to_integer(display_address));
--      if (sigCount = x"00000000") then
--       sigCount <= counter_delay & "00000";
--       display_address <= display_address + 1;
--      else
--       sigCount <= sigCount + 1;
--      end if;
--     end if;
--	 when others => null;
--	end case;
	end if;
  end if;
 end process;
end ArchLEDflashing;
 --------------------------------------------------------------------------------